package com.woniuxy.springboot.mybatis.controller;

import com.woniuxy.springboot.mybatis.bean.R;
import com.woniuxy.springboot.mybatis.pojo.Dept;
import com.woniuxy.springboot.mybatis.service.DeptService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class DeptController {
    @Autowired
    private DeptService deptService;

    @PostMapping("/depts")
    @ApiOperation("新增部门")
    @CrossOrigin
    public R addDept(@RequestBody Dept dept) {
        boolean res = deptService.addDept(dept);
        if (res) {
            return R.ok();
        } else {
            return R.error();
        }
    }

    @DeleteMapping("/depts")
    @ApiOperation("删除部门")
    @CrossOrigin
    public R deleteDept(Integer deptid) {
        boolean res = deptService.deleteDeptById(deptid);
        if (res) {
            return R.ok();
        } else {
            return R.error();
        }
    }
}
